MV_GIGE_GetNetTransInfo

MV_GIGE_GetNetTransInfo

Get network transmission information, including received data size, number of lost frames.

API Definition

int MV_GIGE_GetNetTransInfo(
  void                *handle,
  MV_NETTRANS_INFO    *pstInfo
);

Parameters

handle

[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.

pstInfo

[OUT] Network transmission information, including received data size, number of lost frames, and so on. See MV_NETTRANS_INFO for details.

Return Value

Return MV_OK(0) on success, and return Error Code on failure.

Remarks

Call this API after starting image acquiring through MV_CC_StartGrabbing.

This API is supported only by GigEVision Camera.

The following sample code is for reference only.

using namespace MvCamCtrl;

#define MAX_BUF_SIZE    (1920*1080*3)

void main()
{
     int nRet = -1;
    void* m_handle = NULL;

    //Enumerate all devices corresponding to specified transport protocol within subnet
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //Select the first found online device and create device handle
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    else
    {
        unsigned int nAccessMode = MV_ACCESS_Exclusive;
        unsigned short nSwitchoverKey = 0;

        //Connect device
        nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
        if (MV_OK != nRet)
        {
            printf("error: OpenDevice fail [%x]\n", nRet);
            return;
        }
        //...other processing
    }

    //Start acquiring image
    nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //Get size of one frame
     MVCC_INTVALUE stIntvalue = {0};
    nRet = MV_CC_GetIntValue(m_handle, "PayloadSize", &stIntvalue);
    if (nRet != MV_OK)
    {
        printf("Get PayloadSize failed! nRet [%x]\n", nRet);
        return;
    }
    int nBufSize = stIntvalue.nCurValue; //One frame data size

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(nBufSize);

    MV_FRAME_OUT_INFO stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO));

    MV_NETTRANS_INFO stNetTransInfo = {0};

    //The frequency of calling this interface should be controlled by upper layer application according to frame rate.
    //The codes are for reference only. In practical application, it is recommended to create a new thread for image acquisition and processing.
    while(1)
    {
        if (nTestFrameSize > 99) 
        {
            break;
        }
        nRet = MV_CC_GetOneFrame(m_handle, g_pFrameBuf, MAX_BUF_SIZE, &stInfo);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //...Image data processing

            // Get network transmission information
            if ((nTestFrameSize % 10) == 0)
            {
                nRet = MV_GIGE_GetNetTransInfo(m_handle, &stNetTransInfo);
                if(MV_OK == nRet)
                {
                    printf("GetDataSize [%I64d]\n", stNetTransInfo.nReviceDataSize);
                }
            }

            nTestFrameSize++;
        }
    }

    //...other processing

    //Stop acquiring image
    nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //Shut device and release resource
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //Destroy handle and release resource
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

MV_GIGE_GetNetTransInfo

Get network transmission information, including received data size, number of lost frames.

API Definition

int MV_GIGE_GetNetTransInfo(
  void                *handle,
  MV_NETTRANS_INFO    *pstInfo
);

Parameters

handle

[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.

pstInfo

[OUT] Network transmission information, including received data size, number of lost frames, and so on. See MV_NETTRANS_INFO for details.

Return Value

Return MV_OK(0) on success, and return Error Code on failure.

Remarks

Call this API after starting image acquiring through MV_CC_StartGrabbing.

This API is supported only by GigEVision Camera.

The following sample code is for reference only.

using namespace MvCamCtrl;

#define MAX_BUF_SIZE    (1920*1080*3)

void main()
{
     int nRet = -1;
    void* m_handle = NULL;

    //Enumerate all devices corresponding to specified transport protocol within subnet
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //Select the first found online device and create device handle
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    else
    {
        unsigned int nAccessMode = MV_ACCESS_Exclusive;
        unsigned short nSwitchoverKey = 0;

        //Connect device
        nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
        if (MV_OK != nRet)
        {
            printf("error: OpenDevice fail [%x]\n", nRet);
            return;
        }
        //...other processing
    }

    //Start acquiring image
    nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //Get size of one frame
     MVCC_INTVALUE stIntvalue = {0};
    nRet = MV_CC_GetIntValue(m_handle, "PayloadSize", &stIntvalue);
    if (nRet != MV_OK)
    {
        printf("Get PayloadSize failed! nRet [%x]\n", nRet);
        return;
    }
    int nBufSize = stIntvalue.nCurValue; //One frame data size

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(nBufSize);

    MV_FRAME_OUT_INFO stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO));

    MV_NETTRANS_INFO stNetTransInfo = {0};

    //The frequency of calling this interface should be controlled by upper layer application according to frame rate.
    //The codes are for reference only. In practical application, it is recommended to create a new thread for image acquisition and processing.
    while(1)
    {
        if (nTestFrameSize > 99) 
        {
            break;
        }
        nRet = MV_CC_GetOneFrame(m_handle, g_pFrameBuf, MAX_BUF_SIZE, &stInfo);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //...Image data processing

            // Get network transmission information
            if ((nTestFrameSize % 10) == 0)
            {
                nRet = MV_GIGE_GetNetTransInfo(m_handle, &stNetTransInfo);
                if(MV_OK == nRet)
                {
                    printf("GetDataSize [%I64d]\n", stNetTransInfo.nReviceDataSize);
                }
            }

            nTestFrameSize++;
        }
    }

    //...other processing

    //Stop acquiring image
    nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //Shut device and release resource
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //Destroy handle and release resource
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}